﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
using System.IO;
using System.Configuration;
using System.Web.Script.Services;
using System.Web.Services;
using System.Text.RegularExpressions;
public partial class Admin_CandidateBriefDetails : System.Web.UI.Page
{
    #region events
    public string PathBriefDoc = ConfigurationSettings.AppSettings["BriefDoc"];
    Int32 FileLimitSize = Convert.ToInt32(ConfigurationManager.AppSettings["FileLimitSize"].ToString());
    Int64 VideoSizeLimit = Convert.ToInt64(ConfigurationManager.AppSettings["StimulusSizeLimit"].ToString());

    protected void Page_Load(object sender, EventArgs e)
    {
        txtRegistrationNumber.Attributes.Add("readonly", "readonly");
        txtRegistrationNumber.Style.Add("color", "gray");
        if (!IsPostBack)
        {
            //CalendarExtender1.Format = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB").DateTimeFormat.ShortDatePattern;
            //CalendarExtender2.Format = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB").DateTimeFormat.ShortDatePattern;
            lblFileProposal.InnerText = "* Acceptable file formats " + Convert.ToString(ConfigurationManager.AppSettings["ProposalFileType"]).Replace("|", ",") + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]);
            lblGDDocument.InnerText = "* Acceptable file formats " + Convert.ToString(ConfigurationManager.AppSettings["ProposalFileType"]).Replace("|", ",") + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]);
            lblSTDocument.InnerText = "* Acceptable file formats " + Convert.ToString(ConfigurationManager.AppSettings["VideoFileType"]).Replace("|", ",") + Convert.ToString(ConfigurationManager.AppSettings["StimuluVideoSize"]);
            lblMRResearch.InnerText = "* Acceptable file formats " + Convert.ToString(ConfigurationManager.AppSettings["ProposalFileType"]).Replace("|", ",") + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]);
            lblPastResearch.InnerText = "* Acceptable file formats " + Convert.ToString(ConfigurationManager.AppSettings["ProposalFileType"]).Replace("|", ",") + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]);
            lblContentAnalysis.InnerText = "* Acceptable file formats " + Convert.ToString(ConfigurationManager.AppSettings["ProposalFileType"]).Replace("|", ",") + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]);

            // mvwCandidateBriefDetails.
            mvwCandidateBriefDetails.ActiveViewIndex = 0;
            hdnMenuMoreDetail.Value = "0";
            hdnCandidateStageComplted.Value = "0";
            hdnAssessorCalendarDetailID.Value = "0";
            hdnPartnerID.Value = "0";
            btnPervious.Visible = false;
            mainMenu_MenuItemClick(sender, null);
            hdnBriefID.Value = CommonUtility.Decrypt(Convert.ToString(Request.QueryString["BriefID"]), true);
            LoadBindData();
        }
    }

    public string GetBriefDownload(object objDocumentFile)
    {
        string strPath = string.Empty;
        strPath = Convert.ToString(ConfigurationSettings.AppSettings["BriefDoc"]) + Convert.ToString(objDocumentFile);

        strPath = "javascript:onClickLink('" + strPath.Replace("~", "..") + "')";

        //NavigateUrl="~/upload/briefdocument/adsaf@a.com.docx" 
        return strPath;
    }
    public string GetProposalBriefDocumentDownload(object objProposalDocumentFile)
    {
        string strPathProDoc = string.Empty;
        strPathProDoc = Convert.ToString(ConfigurationSettings.AppSettings["ProposalPath"]) + Convert.ToString(objProposalDocumentFile);
        strPathProDoc = "javascript:onClickLinkProposal('" + strPathProDoc.Replace("~", "..") + "')";
        return strPathProDoc;
    }



    private void LoadBindData()
    {
        try
        {

            DataSet objDs = new DataSet();
            objDs = GetCandidateBriefDetails();

            ActivityMasterBAL objActMstBAL = new ActivityMasterBAL();
            DataSet objjActMstDs = new DataSet();

            objjActMstDs = objActMstBAL.GetActivityByActivityType("SPECIALIZATION");
            CommonUtility.BindDropDown(ref ddlGroupDiscussiontype, objjActMstDs, "ActivityName", "ActivityID");
            CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlGroupDiscussiontype);

            DataSet objCandidateDs = null;
            objCandidateDs = new UserMasterBAL().GetCandidateRegByUserId(CommonUtility.GetLoggedOnUserId());
            CountryMasterBAL objCMBal = new CountryMasterBAL();
            DataSet objDSCountryLanguage = objCMBal.GetCountryLanguageByCountryID(objCandidateDs.Tables[0].Rows[0]["CountryId"]);
            CommonUtility.BindCheckBoxList(ref chkGroupDiscussionLanguage, objDSCountryLanguage, "LanguageName", "LanguageID");
            
            /*LanugageMasterBAL objLangMstBAL = new LanugageMasterBAL();
            objjActMstDs = objLangMstBAL.GetLanguageMasterActive();
            CommonUtility.BindCheckBoxList(ref chkGroupDiscussionLanguage, objjActMstDs, "LanguageName", "LanguageID");*/


            if (objDs.Tables.Count > 0)
            {
                //brief detail table
                if (objDs.Tables[0].Rows.Count > 0)
                {
                    txtHideanBTitle.Text = Convert.ToString(objDs.Tables[0].Rows[0]["BriefTitle"]);
                    tdBriefName.InnerHtml = Convert.ToString(objDs.Tables[0].Rows[0]["BriefTitle"]);
                    tdBriefDesc.InnerHtml = Convert.ToString(objDs.Tables[0].Rows[0]["BriefDesc"]);
                    tdBriefStartDt.InnerHtml = Convert.ToString(objDs.Tables[0].Rows[0]["BriefStartDate"]);
                    tdBriefEndDt.InnerHtml = Convert.ToString(objDs.Tables[0].Rows[0]["BriefEndDate"]);
                    hdnCandidateStatus.Value = Convert.ToString(objDs.Tables[0].Rows[0]["CandidateStatusID"]);
                    hdnCandidateBriefId.Value = Convert.ToString(objDs.Tables[0].Rows[0]["CandidateBriefID"]);
                    hdnCandidateID.Value = Convert.ToString(objDs.Tables[0].Rows[0]["CandidateID"]);
                    hdnCandidateStageComplted.Value = Convert.ToString(objDs.Tables[0].Rows[0]["CandidateStageComplted"]);
                    hdnPartnerID.Value = Convert.ToString(objDs.Tables[0].Rows[0]["PartnerIntID"]);
                    if (hdnCandidateStageComplted.Value.Trim() == "")
                    { hdnCandidateStageComplted.Value = "0"; }

                    if (Convert.ToInt64(objDs.Tables[0].Rows[0]["PartnerIntID"]) > 0)
                    {
                        trCandidatePreference1.Visible = false;
                        //brijal change as on 08112017
                        //trCandidatePreference1.Visible = true;
                        trCandidatePreference2.Visible = true;
                        trCandidatePreference3.Visible = true;

                        if (Convert.ToString(objDs.Tables[0].Rows[0]["AccrediationType"]) == "CANM")
                        {
                            tdCandidatePreference1.InnerHtml = "Research Lead Only";
                        }
                        else
                        {
                            tdCandidatePreference1.InnerHtml = "Moderator Only";
                        }
                        DataSet objPartnetDs = new UserMasterBAL().GetCandidateDetailsByRegNum(objDs.Tables[0].Rows[0]["ParternerRegistrationNo"].ToString());
                        string strPartnerDetail = objPartnetDs.Tables[0].Rows[0]["CandidateName"].ToString() + " [ " + objDs.Tables[0].Rows[0]["ParternerRegistrationNo"].ToString() + " ]";
                        tdCandidatePreference2.InnerHtml = Convert.ToString(strPartnerDetail);
                        //brijal change as on 08112017
                        //tdCandidatePreference2.InnerHtml = Convert.ToString(objDs.Tables[0].Rows[0]["ParternerRegistrationNo"]);
                    }
                    else
                    {
                        if (Convert.ToString(objDs.Tables[0].Rows[0]["AccrediationType"]) == "CANB")
                        {
                            trCandidatePreference1.Visible = false;
                            trCandidatePreference2.Visible = false;
                            trCandidatePreference3.Visible = false;
                        }
                        else
                        {
                            trCandidatePreference1.Visible = false;
                            //brijal change as on 08112017
                            //trCandidatePreference1.Visible = true;
                            tdCandidatePreference1.InnerText = "Alone";
                            trCandidatePreference2.Visible = false;
                            trCandidatePreference3.Visible = false;
                        }
                    }

                }
                else
                {
                    hdnCandidateStatus.Value = "0";
                    hdnStageMode.Value = "0";
                    btnNext.Visible = false;
                }

                //brief docuemnt details 
                if (objDs.Tables[1].Rows.Count > 0)
                {
                    grdBriefDocument.DataSource = objDs.Tables[1];
                    grdBriefDocument.DataBind();
                }

                //candidate query against breif 
                if (objDs.Tables[2].Rows.Count > 0)
                {
                    DataView objDv = new DataView();
                    objDv = objDs.Tables[2].DefaultView;
                    objDv.RowFilter = "QueryTypeID  = 1";
                    if (objDv.Count > 0)
                    {
                        trQuestion.Visible = true;
                        trQuestionSpace1.Visible = true;
                        trAssessorComments.Visible = true;
                        rbtQuestion.Items[0].Selected = true;
                        trQuestionSpace2.Visible = true;
                        txtQuestionAssessor.Text = Convert.ToString(objDv[0]["Query"]);
                        lblQuestionAssessor.Text = Convert.ToString(objDv[0]["QueryDate"]);
                        txtAssessorComments.Text = Convert.ToString(objDv[0]["Answer"]);
                        lblAssessorComments.Text = Convert.ToString(objDv[0]["AnswerDate"]);
                    }
                    else
                    {
                        trQuestion.Visible = false;
                        trQuestionSpace1.Visible = false;
                        trAssessorComments.Visible = false;
                        rbtQuestion.Items[1].Selected = true;
                        trQuestionSpace2.Visible = false;

                    }


                    if (Convert.ToString(objDs.Tables[0].Rows[0]["CandidateActivityCode"]) == "CANB")
                    {
                        // objDv.RowFilter = "QueryTypeID  = 2"; //ankit patel 06/11/2015
                        objDv.RowFilter = "QueryTypeID  = 3";
                        if (objDv.Count > 0)
                        {
                            //mainMenu.Items[mainMenu.Items.Count - 1].Text = "Moderator Question"; //ankit patel 06/11/2015
                            mainMenu.Items[mainMenu.Items.Count - 1].Text = "Assessor Question";
                            hdnMenuMoreDetail.Value = Convert.ToString(objDv[0]["CandidateQueryID"]);
                            txtQuestionMore.Text = Convert.ToString(objDv[0]["Query"]);
                            lblQuestionMore.Text = Convert.ToString(objDv[0]["QueryDate"]);
                            txtCommentsMore.Text = Convert.ToString(objDv[0]["Answer"]);
                            lblCommentsMore.Text = Convert.ToString(objDv[0]["AnswerDate"]);
                            hdnCandidateQueryID.Value = Convert.ToString(objDv[0]["QueryTypeID"]);
                            if (txtCommentsMore.Text.Trim().Length == 0)
                            {
                                txtCommentsMore.Enabled = true;
                                btnMoreCommentAdd.Enabled = true;
                                btnMoreCommentAdd.Visible = true;
                                btnMoreCommentCancel.Enabled = true;
                                btnMoreCommentCancel.Visible = true;
                            }
                            else
                            {
                                txtCommentsMore.Enabled = false;
                                btnMoreCommentAdd.Enabled = false;
                                btnMoreCommentAdd.Visible = false;
                                btnMoreCommentCancel.Enabled = false;
                                btnMoreCommentCancel.Visible = false;
                            }
                        }
                    }


                    if (Convert.ToString(objDs.Tables[0].Rows[0]["CandidateActivityCode"]) == "CANR")
                    {
                        objDv.RowFilter = "QueryTypeID  = 3";
                        if (objDv.Count > 0)
                        {
                            mainMenu.Items[mainMenu.Items.Count - 1].Text = "Research Lead Question";
                            hdnMenuMoreDetail.Value = Convert.ToString(objDv[0]["CandidateQueryID"]);
                            txtQuestionMore.Text = Convert.ToString(objDv[0]["Query"]);
                            txtCommentsMore.Text = Convert.ToString(objDv[0]["Answer"]);
                            hdnCandidateQueryID.Value = Convert.ToString(objDv[0]["QueryTypeID"]);
                            if (txtCommentsMore.Text.Trim().Length == 0)
                            {
                                txtCommentsMore.Enabled = true;
                                btnMoreCommentAdd.Enabled = true;
                                btnMoreCommentAdd.Visible = true;
                                btnMoreCommentCancel.Enabled = true;
                                btnMoreCommentCancel.Visible = true;
                            }
                            else
                            {
                                txtCommentsMore.Enabled = false;
                                btnMoreCommentAdd.Enabled = false;
                                btnMoreCommentAdd.Visible = false;
                                btnMoreCommentCancel.Enabled = false;
                                btnMoreCommentCancel.Visible = false;
                            }
                        }
                    }

                }
                else
                {
                    trQuestion.Visible = false;
                    trQuestionSpace1.Visible = false;
                    trQuestionSpace2.Visible = false;
                    trAssessorComments.Visible = false;
                    rbtQuestion.Items[1].Selected = true;
                }

                if (objDs.Tables[3].Rows.Count > 0)
                {
                    DataView objDv = new DataView();
                    objDv = objDs.Tables[3].DefaultView;
                    objDv.RowFilter = "DocumentTypeID  = 1";
                    if (objDv.Count > 0)
                    {
                        gvProposalDocument.DataSource = objDv;
                        gvProposalDocument.DataBind();
                    }
                    objDv.RowFilter = "DocumentTypeID  = 2";
                    if (objDv.Count > 0)
                    {
                        gvGDDocument.DataSource = objDv;
                        gvGDDocument.DataBind();
                    }


                    objDv.RowFilter = "DocumentTypeID  = 3";
                    if (objDv.Count > 0)
                    {
                        gvContentAnalysis.DataSource = objDv;
                        gvContentAnalysis.DataBind();
                    }

                    objDv.RowFilter = "DocumentTypeID  = 4";
                    if (objDv.Count > 0)
                    {
                        gvPastResearch.DataSource = objDv;
                        gvPastResearch.DataBind();
                    }

                    objDv.RowFilter = "DocumentTypeID  = 5";
                    if (objDv.Count > 0)
                    {
                        gvMRResearch.DataSource = objDv;
                        gvMRResearch.DataBind();
                    }

                    objDv.RowFilter = "DocumentTypeID  = 10";
                    if (objDv.Count > 0)
                    {
                        gvStDocument.DataSource = objDv;
                        gvStDocument.DataBind();
                    }

                }

                
                

                //remove more details
                if (hdnMenuMoreDetail.Value == "0")
                {
                    mainMenu.Items.Remove(mainMenu.Items[6]);
                }
                else
                {
                    mainMenu.Items[6].Enabled = false;
                }

                //brijal remove tabs as on 15-11-2017
                mainMenu.Items.Remove(mainMenu.Items[5]);
                mainMenu.Items.Remove(mainMenu.Items[4]);

                if (objDs.Tables[4].Rows.Count > 0)
                {

                    DataView objDv = new DataView();
                    objDv = objDs.Tables[4].DefaultView;

                    //ddlInternal_External.SelectedIndex = ddlInternal_External.Items.IndexOf(ddlInternal_External.Items.FindByValue(Convert.ToString(objDv[0]["GDModeratorType"])));
                    ddlGroupDiscussiontype.SelectedIndex = ddlGroupDiscussiontype.Items.IndexOf(ddlGroupDiscussiontype.Items.FindByValue(Convert.ToString(objDv[0]["GDTypeID"])));

                    //if (ddlInternal_External.SelectedValue == "1")
                    //{
                    //    trCandidateName.Visible = true;
                    //    trRegistrationNumber.Visible = true;
                    //    trAssessorName.Visible = false;
                    //    trBlankRowCandidateName.Visible = true;
                    //    trBlankRowRegistrationNumber.Visible = true;
                    //}
                    //else if (ddlInternal_External.SelectedValue == "2")
                    //{
                    //    trCandidateName.Visible = false;
                    //    trRegistrationNumber.Visible = false;
                    //    trBlankRowCandidateName.Visible = false;
                    //    trBlankRowRegistrationNumber.Visible = false;
                    //    trAssessorName.Visible = true;
                    //}
                    //else
                    //{
                    //    trCandidateName.Visible = false;
                    //    trRegistrationNumber.Visible = false;
                    //    trAssessorName.Visible = false;
                    //    trBlankRowCandidateName.Visible = false;
                    //    trBlankRowRegistrationNumber.Visible = false;
                    //}


                    string[] languagelist = (Convert.ToString(objDv[0]["GDLanguageList"])).Split(',');


                    for (int j = 0; j < languagelist.Count(); j++)
                    {
                        for (int i = 0; i < chkGroupDiscussionLanguage.Items.Count; i++)
                        {
                            if (chkGroupDiscussionLanguage.Items[i].ToString() == languagelist[j].Trim())
                            {
                                chkGroupDiscussionLanguage.Items[i].Selected = true;
                            }
                        }
                    }

                    hdnAssessorCalendarDetailID.Value = Convert.ToString(objDv[0]["AssessorCalendarDetailID"]) == "" ? "0" : Convert.ToString(objDv[0]["AssessorCalendarDetailID"]);
                    hdnGDCandidateID.Value = Convert.ToString(objDv[0]["GDCandidateID"]);
                    hdnCandidateGDID.Value = Convert.ToString(objDv[0]["CandidateGDID"]);

                    if (objDv[0]["GDCandidateTime"].ToString().Trim() != "" && objDv[0]["GDCandidateTime"].ToString().Trim() != String.Empty)
                    {
                        ddlHour.SelectedIndex = ddlHour.Items.IndexOf(ddlHour.Items.FindByValue(Convert.ToString(objDv[0]["GDCandidateHour"])));
                        ddlMinute.SelectedIndex = ddlMinute.Items.IndexOf(ddlMinute.Items.FindByValue(Convert.ToString(TimeSpan.Parse(objDv[0]["GDCandidateTime"].ToString()).Minutes)));

                        if (TimeSpan.Parse(objDv[0]["GDCandidateTime"].ToString()).Hours >= 12)
                        {
                            ddlAMPM.SelectedValue = "PM";
                        }
                        else
                        {
                            ddlAMPM.SelectedValue = "AM";
                        }
                    }

                    txtGroupDiscussionLocation.Text = Convert.ToString(objDv[0]["GDLocation"]);
                    txtCandidateName.Text = Convert.ToString(objDv[0]["UserName"]);
                    txtRegistrationNumber.Text = Convert.ToString(objDv[0]["RegistrationNO"]);
                    txtRegistrationNumber.Attributes.Add("readonly", "readonly");
                    txtRegistrationNumber.Style.Add("color", "gray");
                    txtAssessorName.Text = Convert.ToString(objDv[0]["ExternalAssessorName"]);

                }

                if (objDs.Tables[5].Rows.Count > 0)
                {
                    gvCandidateSelectAssessordate.DataSource = objDs.Tables[5];
                    gvCandidateSelectAssessordate.DataBind();

                    grdPropAssessorAvailable.DataSource = objDs.Tables[5];
                    grdPropAssessorAvailable.DataBind();

                    if (objDs.Tables[5].Rows.Count == 1)
                    {
                        if (hdnCandidateStatus.Value == "6")
                        {
                            hdnCanGDDate.Value = Convert.ToString(objDs.Tables[5].Rows[0]["CanGDDate"]);
                        }
                    }
                    DataSet ds1 = GetAssessorCalendarUpdateLog(Convert.ToInt64(hdnCandidateID.Value));
                    if (ds1.Tables.Count > 0)
                    {    
                        if (ds1.Tables[0].Rows.Count > 0)
                        {   
                            vOldGDDateH.Visible = true;
                            vOldGDDateG.Visible = true;
                            gvCandidateOldGD.DataSource = ds1.Tables[0];
                            gvCandidateOldGD.DataBind();
                        }
                        if (ds1.Tables[1].Rows.Count > 0)
                        {
                            vNwGDDateH.Visible = true;
                            vNwGDDateG.Visible = true;                            
                            gvCandidateGD.DataSource = ds1.Tables[1];
                            gvCandidateGD.DataBind();
                        }
                        //brijal change as on 26-05-2017
                        DataSet dsCalenderEnabled = new CandidateBriefDetailBAL().GetCandidateCalendarUpdateByAssessorFlg(CommonUtility.GetLoggedOnUserId());
                        if (dsCalenderEnabled.Tables[0].Rows[0][0].ToString() == "TRUE")
                        {
                            foreach (GridViewRow item in gvCandidateSelectAssessordate.Rows)
                            {
                                CheckBox chkCandidateFirstHalf = (CheckBox)item.FindControl("chkCandidateFirstHalf");
                                CheckBox chkCandidateSecondHalf = (CheckBox)item.FindControl("chkCandidateSecondHalf");
                                chkCandidateFirstHalf.Enabled = false;
                                chkCandidateSecondHalf.Enabled = false;
                            }
                        }
                    }
                    else
                    {
                        vNwGDDateH.Visible = false;
                        vNwGDDateG.Visible = false;
                        vOldGDDateH.Visible = false;
                        vOldGDDateG.Visible = false;
                    }
                }
                else
                {
                    gvCandidateSelectAssessordate.DataSource = null;
                    gvCandidateSelectAssessordate.DataBind();

                    grdPropAssessorAvailable.DataSource = null;
                    grdPropAssessorAvailable.DataBind();
                    tdPropAssessorAvailable.Visible = false;
                }

                StageWiseDisable(false);

            }
            else
            {
                hdnCandidateStatus.Value = "0";
                hdnStageMode.Value = "0";
                btnNext.Visible = false;
            }

        }
        catch (Exception ex)
        {
            ex.AddErrorToLog();// throw ex;
        }
    }

    private DataSet GetAssessorCalendarUpdateLog(Int64 CandidateId)
    {
        DataSet objDs = null;
        try
        {
            //todo  CommonUtility.GetLoggedOnUserId()
            objDs = new CandidateBriefDetailBAL().GetAssessorCalendarUpdateLog(CandidateId);

        }
        catch (Exception exception)
        {
            exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;

    }

    [WebMethod]
    public static List<string> GetCandidateName(string prefixText)
    {
        DataSet objDs = null;
        List<string> candidates = new List<string>();
        try
        {
            CandidateBriefDetailBAL objCBDBAL = new CandidateBriefDetailBAL();
            objDs = objCBDBAL.GetCandidateName(prefixText);

            foreach (DataRow item in objDs.Tables[0].Rows)
            {
                candidates.Add(Convert.ToString(item["CandidateName"]));
            }
        }
        catch (Exception ex)
        {
            ex.AddErrorToLog();
        }
        return candidates;
    }

    protected void gvCandidateSelectAssessordate_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        int rwIndex = 0;
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            rwIndex = e.Row.RowIndex + (gvCandidateSelectAssessordate.PageSize * gvCandidateSelectAssessordate.PageIndex);
            DataTable DtObj = (DataTable)gvCandidateSelectAssessordate.DataSource;
            CheckBox chkApproveFirstHalf = (CheckBox)e.Row.FindControl("chkApproveFirstHalf");
            CheckBox chkApproveSecondHalf = (CheckBox)e.Row.FindControl("chkApproveSecondHalf");
            CheckBox chkCandidateFirstHalf = (CheckBox)e.Row.FindControl("chkCandidateFirstHalf");
            CheckBox chkCandidateSecondHalf = (CheckBox)e.Row.FindControl("chkCandidateSecondHalf");
            Label lblFHHour = (Label)e.Row.FindControl("lblFHHour");
            Label lblFHMinute = (Label)e.Row.FindControl("lblFHMinute");
            Label lblSHHour = (Label)e.Row.FindControl("lblSHHour");
            Label lblSHMinute = (Label)e.Row.FindControl("lblSHMinute");
            Label lblAssessorCalendarDetailID = (Label)e.Row.FindControl("lblAssessorCalendarDetailID");

            chkApproveFirstHalf.Checked = Convert.ToBoolean(DtObj.Rows[rwIndex]["FirstHalfCheck"]);
            chkApproveSecondHalf.Checked = Convert.ToBoolean(DtObj.Rows[rwIndex]["SecondHalfCheck"]);
            lblAssessorCalendarDetailID.Text = DtObj.Rows[rwIndex]["AssessorCalendarDetailID"].ToString();

            chkCandidateFirstHalf.Enabled = false;
            chkCandidateSecondHalf.Enabled = false;


            lblFHHour.Text = TimeSpan.Parse(DtObj.Rows[rwIndex]["FirstHalfTime"].ToString()).Hours.ToString("00");
            lblFHMinute.Text = TimeSpan.Parse(DtObj.Rows[rwIndex]["FirstHalfTime"].ToString()).Minutes.ToString("00");
            lblSHHour.Text = CommonUtility.GetHour(TimeSpan.Parse(DtObj.Rows[rwIndex]["SecondHalfTime"].ToString()).Hours).ToString("00");
            lblSHMinute.Text = TimeSpan.Parse(DtObj.Rows[rwIndex]["SecondHalfTime"].ToString()).Minutes.ToString("00");

            chkCandidateFirstHalf.Checked = Convert.ToBoolean(DtObj.Rows[rwIndex]["CandidateFirstHalfCheck"]);
            chkCandidateSecondHalf.Checked = Convert.ToBoolean(DtObj.Rows[rwIndex]["CandidateSecondHalfCheck"]);

            if (hdnCandidateStatus.Value == "6")
            {   
                DateTime NewDate = Convert.ToDateTime(DtObj.Rows[rwIndex]["FirstHalfTime"].ToString()).AddHours(1);
                chkCandidateFirstHalf.Attributes.Add("Time", NewDate.ToString("hh:mm:tt"));
                chkCandidateFirstHalf.Enabled = chkApproveFirstHalf.Checked;
                if (chkApproveFirstHalf.Checked == false)
                    chkCandidateFirstHalf.Style.Add("display", "none");

                NewDate = Convert.ToDateTime(DtObj.Rows[rwIndex]["SecondHalfTime"].ToString()).AddHours(1);
                chkCandidateSecondHalf.Attributes.Add("Time", NewDate.ToString("hh:mm:tt"));
                chkCandidateSecondHalf.Enabled = chkApproveSecondHalf.Checked;
                if (chkApproveSecondHalf.Checked == false)
                    chkCandidateSecondHalf.Style.Add("display", "none");
                
            }
            
            chkApproveFirstHalf.Style.Add("display", "none");
            chkApproveSecondHalf.Style.Add("display", "none");
            chkApproveFirstHalf.Enabled = false;
            chkApproveSecondHalf.Enabled = false;

        }
    }


    private void StageWiseDisable(bool PreviousMoveFlg)
    {
        hdnGDStageMode.Value = "0";
        if (hdnCandidateStatus.Value == "22")
        {
            hdnStageMode.Value = "1";
            txtQuestionAssessor.Enabled = true;
            regQuestionAssessor.Enabled = true;
            txtAssessorComments.Enabled = false;
            rbtQuestion.Enabled = true;
            chkConfirm.Enabled = true;
            chkConfirm.Checked = false;
            grdBriefDocument.Enabled = true;
        }
        else
        {
            txtQuestionAssessor.Enabled = false;
            regQuestionAssessor.Enabled = false;
            txtAssessorComments.Enabled = false;
            hdnStageMode.Value = "0";
            rbtQuestion.Enabled = false;
            chkConfirm.Enabled = false;
            chkConfirm.Checked = true;

            grdBriefDocument.Enabled = false;
        }


        if (hdnCandidateStatus.Value == "5")
        {
            hdnProposalStageMode.Value = "1";
            filProposal.Enabled = true;
            lblUploadAlert.Visible = true;
            txtComments.Enabled = true;
            btnProposal.Enabled = true;
            chkProposal.Enabled = true;
            chkProposal.Checked = false;
            btnCancelProposal.Enabled = true;
            gvProposalDocument.Columns[3].Visible = true;
            grdPropAssessorAvailable.Visible = true;
            tdPropAssessorAvailable.Visible = true;

        }
        else
        {
            hdnProposalStageMode.Value = "0";
            filProposal.Enabled = false;
            lblUploadAlert.Visible = false;
            txtComments.Enabled = false;
            btnCancelProposal.Enabled = false;
            btnProposal.Enabled = false;
            chkProposal.Enabled = false;
            chkProposal.Checked = true;
            gvProposalDocument.Columns[3].Visible = false;
            grdPropAssessorAvailable.Visible = false;
            tdPropAssessorAvailable.Visible = false;
        }


        if (hdnCandidateStatus.Value == "6")
        {
            hdnGDStageMode.Value = "1";
            filGDDocument.Enabled = true;

            chkGDDocument.Enabled = true;
            chkGDDocument.Checked = false;



            //ddlInternal_External.Enabled = true;
            txtCandidateName.Enabled = true;
            txtRegistrationNumber.Attributes.Add("readonly", "readonly");
            txtRegistrationNumber.Style.Add("color", "gray");
            txtAssessorName.Enabled = true;
            filGDDocument.Enabled = true;
            btnGDDocument.Enabled = true;
            gvGDDocument.Columns[3].Visible = true;
            if (hdnCanGDDate.Value.Length > 0)
            {
                if (Convert.ToDateTime(hdnCanGDDate.Value) < System.DateTime.Today)
                {
                    btnSave.Enabled = false;
                    btnCancel.Enabled = false;
                    ddlGroupDiscussiontype.Enabled = false;
                    chkGroupDiscussionLanguage.Enabled = false;
                    txtGroupDiscussionLocation.Enabled = false;
                    ddlHour.Enabled = false;
                    ddlMinute.Enabled = false;
                    ddlAMPM.Enabled = false;
                }
                else
                {
                    ddlGroupDiscussiontype.Enabled = true;
                    chkGroupDiscussionLanguage.Enabled = true;
                    txtGroupDiscussionLocation.Enabled = true;
                    btnSave.Enabled = true;
                    btnCancel.Enabled = true;
                    ddlHour.Enabled = true;
                    ddlMinute.Enabled = true;
                    ddlAMPM.Enabled = true;
                }
            }
            else
            {
                ddlGroupDiscussiontype.Enabled = true;
                chkGroupDiscussionLanguage.Enabled = true;
                txtGroupDiscussionLocation.Enabled = true;
                btnSave.Enabled = true;
                btnCancel.Enabled = true;
                ddlHour.Enabled = true;
                ddlMinute.Enabled = true;
                ddlAMPM.Enabled = true;
            }

            //ddlInternal_External.SelectedValue = "0";
            trCandidateName.Visible = false;
            trRegistrationNumber.Visible = false;
            trAssessorName.Visible = false;
            trBlankRowCandidateName.Visible = false;
            trBlankRowRegistrationNumber.Visible = false;
            filStuDocument.Enabled = true;
            btnStuDocument.Enabled = true;

            if (mvwCandidateBriefDetails.ActiveViewIndex == 1)
            {
                tdPreFinish.Visible = true;
                tdActionPanel.Style.Add("text-align", "right");
            }
            else
            {
                tdPreFinish.Visible = false;
                tdActionPanel.Style.Add("text-align", "center");
            }
        }
        else
        {
            //hdnGDStageMode.Value = "0";
            filGDDocument.Enabled = false;

            btnGDDocument.Enabled = false;
            gvGDDocument.Columns[3].Visible = false;
            chkGDDocument.Enabled = false;
            chkGDDocument.Checked = true;
            ddlGroupDiscussiontype.Enabled = false;

            chkGroupDiscussionLanguage.Enabled = false;
            txtGroupDiscussionLocation.Enabled = true;

            //if (ddlInternal_External.SelectedValue == "1")
            //{
            //    trCandidateName.Visible = true;
            //    trRegistrationNumber.Visible = true;
            //    trAssessorName.Visible = false;
            //    trBlankRowCandidateName.Visible = true;
            //    trBlankRowRegistrationNumber.Visible = true;
            //}
            //else if (ddlInternal_External.SelectedValue == "2")
            //{
            //    trCandidateName.Visible = false;
            //    trRegistrationNumber.Visible = false;
            //    trAssessorName.Visible = true;
            //    trBlankRowCandidateName.Visible = false;
            //    trBlankRowRegistrationNumber.Visible = false;
            //}
            //else
            //{
            //    trCandidateName.Visible = false;
            //    trRegistrationNumber.Visible = false;
            //    trAssessorName.Visible = false;
            //    trBlankRowCandidateName.Visible = false;
            //    trBlankRowRegistrationNumber.Visible = false;
            //}

            ddlHour.Enabled = false;
            ddlMinute.Enabled = false;
            ddlAMPM.Enabled = false;
            //ddlInternal_External.Enabled = false;
            txtCandidateName.Enabled = false;

            txtAssessorName.Enabled = false;
            filGDDocument.Enabled = false;
            filStuDocument.Enabled = false;
            btnStuDocument.Enabled = false;
            btnSave.Enabled = true;
            btnCancel.Enabled = false;

            tdPreFinish.Visible = false;
            tdActionPanel.Style.Add("text-align", "center");
        }


        if (hdnCandidateStatus.Value == "7")
        {
            hdnGDStageMode.Value = "1";
            hdnCAStageMode.Value = "1";
            fileContentAnalysis.Enabled = true;
            txtContentAnalysis.Enabled = true;
            btnContentAnalysis.Enabled = true;
            //chkContentAnalysis.Enabled = true;
            //chkContentAnalysis.Checked = false;
            gvContentAnalysis.Columns[3].Visible = true;
            gvContentAnalysis.Enabled = true;
            btnCancelContentAnalysis.Enabled = true;
            if ((mvwCandidateBriefDetails.ActiveViewIndex == 1 || mvwCandidateBriefDetails.ActiveViewIndex == 2 ||
                mvwCandidateBriefDetails.ActiveViewIndex == 3 || mvwCandidateBriefDetails.ActiveViewIndex == 4)
                && PreviousMoveFlg == false)
            {
                tdPreFinish.Visible = true;
                tdActionPanel.Style.Add("text-align", "right");
            }
            else if ((/*mvwCandidateBriefDetails.ActiveViewIndex == 2 ||*/ mvwCandidateBriefDetails.ActiveViewIndex == 3 ||
                mvwCandidateBriefDetails.ActiveViewIndex == 4 || mvwCandidateBriefDetails.ActiveViewIndex == 5)
                && PreviousMoveFlg)
            {
                tdPreFinish.Visible = true;
                tdActionPanel.Style.Add("text-align", "right");
            }
            else
            {
                tdPreFinish.Visible = false;
                tdActionPanel.Style.Add("text-align", "center");
            }
        }
        else
        {
            hdnCAStageMode.Value = "0";
            fileContentAnalysis.Enabled = false;
            txtContentAnalysis.Enabled = false;
            btnContentAnalysis.Enabled = false;
            //chkContentAnalysis.Enabled = false;
            gvContentAnalysis.Enabled = false;
            //chkContentAnalysis.Checked = true;
            btnCancelContentAnalysis.Enabled = false;
            gvContentAnalysis.Columns[3].Visible = false;


        }


        if (hdnCandidateStatus.Value == "8")
        {
            hdnGDStageMode.Value = "1";
            hdnMRStageMode.Value = "1";
            fileContentAnalysis.Enabled = true;
            btnContentAnalysis.Enabled = true;
            // filePastResearch.Enabled = true;
            fileMRResearch.Enabled = true;
            txtPastResearch.Enabled = true;
            txtMRResearch.Enabled = true;
            btnAddMRResearch.Enabled = true;
            // btnAddPastResearch.Enabled = true;
            //chkMRResearch.Enabled = true;
            //chkMRResearch.Checked = false;
            gvMRResearch.Columns[3].Visible = true;
            gvMRResearch.Enabled = true;
            gvPastResearch.Enabled = true;
            gvPastResearch.Columns[3].Visible = true;
            btnCancelMRResearch.Enabled = true;
            btnCancelPastResearch.Enabled = true;
            if ((mvwCandidateBriefDetails.ActiveViewIndex == 1 || mvwCandidateBriefDetails.ActiveViewIndex == 2 ||
                mvwCandidateBriefDetails.ActiveViewIndex == 3 || mvwCandidateBriefDetails.ActiveViewIndex == 4) 
                && PreviousMoveFlg == false)
            {
                tdPreFinish.Visible = true;
                tdActionPanel.Style.Add("text-align", "right");
            }
            else if ((/*mvwCandidateBriefDetails.ActiveViewIndex == 2 ||*/ mvwCandidateBriefDetails.ActiveViewIndex == 3 ||
                mvwCandidateBriefDetails.ActiveViewIndex == 4 || mvwCandidateBriefDetails.ActiveViewIndex == 5)
                && PreviousMoveFlg)
            {
                tdPreFinish.Visible = true;
                tdActionPanel.Style.Add("text-align", "right");
            }
            else
            {
                tdPreFinish.Visible = false;
                tdActionPanel.Style.Add("text-align", "center");
            }
        }
        else
        {
            hdnMRStageMode.Value = "0";
            //filePastResearch.Enabled = false;
            fileMRResearch.Enabled = false;
            txtPastResearch.Enabled = false;
            txtMRResearch.Enabled = false;
            btnAddMRResearch.Enabled = false;
            //btnAddPastResearch.Enabled = false;
            //chkMRResearch.Enabled = false;
            //chkMRResearch.Checked = true;
            gvMRResearch.Enabled = false;
            gvPastResearch.Enabled = false;
            btnCancelMRResearch.Enabled = false;
            btnCancelPastResearch.Enabled = false;
            gvMRResearch.Columns[3].Visible = false;
            gvPastResearch.Columns[3].Visible = false;
        }


        //last stage
        if (hdnCandidateStatus.Value == "24")
        {
            // mainMenu.Items.Remove(mainMenu.Items[6]);
            //brijal added as on 28022017 for after Finish click document upload enable
            fileContentAnalysis.Enabled = true;
            btnContentAnalysis.Enabled = true;
            filePastResearch.Enabled = true;
            btnAddPastResearch.Enabled = true;
            fileMRResearch.Enabled = true;
            btnAddMRResearch.Enabled = true;
        }
        else
        {

        }

        if (((IList<int>)new[] { 6, 7, 8, 9, 24, 10, 11, 12, 13, 14, 15, 16, 17 }).Contains(Convert.ToInt16(hdnCandidateStatus.Value)))
        {
            filePastResearch.Enabled = true;
            btnAddPastResearch.Enabled = true;
            filStuDocument.Enabled = true;
            btnStuDocument.Enabled = true;
        }
        else
        {
            filePastResearch.Enabled = false;
            btnAddPastResearch.Enabled = false;
            filStuDocument.Enabled = false;
            btnStuDocument.Enabled = false;
        }

    }

    protected void mainMenu_MenuItemClick(object sender, MenuEventArgs e)
    {
        int intActiveIndex;
        if (e != null)
        {
            mvwCandidateBriefDetails.ActiveViewIndex = Int32.Parse(e.Item.Value);
        }

        intActiveIndex = mvwCandidateBriefDetails.ActiveViewIndex;

        switch (intActiveIndex)
        {
            case 0:

                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = false;
                mainMenu.Items[2].Enabled = false;
                mainMenu.Items[3].Enabled = false;
                /*mainMenu.Items[4].Enabled = false;
                mainMenu.Items[5].Enabled = false;*/

                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                { mainMenu.Items[6].Enabled = false; }

                btnPervious.Visible = false;
                btnNext.Visible = true;
                btnNext.Text = "Next";

                break;
            case 1:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = false;
                mainMenu.Items[3].Enabled = false;
                /*mainMenu.Items[4].Enabled = false;
                mainMenu.Items[5].Enabled = false;*/

                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                { mainMenu.Items[6].Enabled = false; }

                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnNext.Text = "Next";
                break;
            case 2:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = false;
                /*mainMenu.Items[4].Enabled = false;
                mainMenu.Items[5].Enabled = false;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                { mainMenu.Items[6].Enabled = false; }

                // mainMenu.Items[6].Enabled = false;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnNext.Text = "Next";
                break;
            case 3:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                /*mainMenu.Items[4].Enabled = false;
                mainMenu.Items[5].Enabled = false;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                { mainMenu.Items[6].Enabled = false; }
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnNext.Text = "Next";
                break;
            case 4:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                /*mainMenu.Items[4].Enabled = true;
                mainMenu.Items[5].Enabled = false;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                { mainMenu.Items[6].Enabled = false; }
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnNext.Text = "Next";
                break;
            case 5:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                /*mainMenu.Items[4].Enabled = true;
                mainMenu.Items[5].Enabled = true;*/

                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                {
                    mainMenu.Items[6].Enabled = false;
                    btnNext.Text = "Next";
                    btnNext.Visible = true;
                }
                else
                {

                    if (hdnCandidateStageComplted.Value == "24")
                    {
                        btnNext.Text = "Finish";
                        btnNext.Visible = false;
                    }
                    else
                    {
                        btnNext.Text = "Finish";
                        btnNext.Visible = true;
                    }
                }
                btnPervious.Visible = true;

                break;
            case 6:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                /*mainMenu.Items[4].Enabled = true;
                mainMenu.Items[5].Enabled = true;*/
                mainMenu.Items[6].Enabled = true;
                btnPervious.Visible = true;
                btnNext.Visible = false;
                break;
            //case 7:
            //    mainMenu.Items[0].Enabled = true;
            //    mainMenu.Items[1].Enabled = true;
            //    mainMenu.Items[2].Enabled = true;
            //    mainMenu.Items[3].Enabled = true;
            //    mainMenu.Items[4].Enabled = true;
            //    mainMenu.Items[5].Enabled = true;
            //    mainMenu.Items[6].Enabled = true;
            //    mainMenu.Items[7].Enabled = true;

            // break;
        }
    }


    protected void btnNext_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            NextBothClick();
        }
    }


    protected void btnPervious_Click(object sender, EventArgs e)
    {
        PreviousBothClick();
    }


    protected void btnProposal_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            try
            {
                SaveDocument("PROPOSAL");
                txtComments.Text = "";
            }
            catch (Exception ex)
            {
                lblMessage.Text = "Error while saving Record : " + ex.Message;

            }
            finally
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Proposal Document Uploaded Successfully.');", true);
            }

        }

    }

    #endregion


    private void PreviousBothClick()
    {
        switch (mvwCandidateBriefDetails.ActiveViewIndex)
        {
            case 1:
                StageWiseDisable(true);
                mvwCandidateBriefDetails.ActiveViewIndex = 0;
                btnPervious.Visible = false;
                btnNext.Visible = true;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = false;
                mainMenu.Items[2].Enabled = false;
                mainMenu.Items[3].Enabled = false;
                /*mainMenu.Items[4].Enabled = false;
                mainMenu.Items[5].Enabled = false;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                {
                    mainMenu.Items[6].Enabled = false;

                }
                btnNext.Text = "Next";
                //mainMenu.Items[7].Enabled = false;
                break;
            case 2:
                StageWiseDisable(true);
                mvwCandidateBriefDetails.ActiveViewIndex = 1;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = false;
                mainMenu.Items[3].Enabled = false;
                /*mainMenu.Items[4].Enabled = false;
                mainMenu.Items[5].Enabled = false;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                {
                    mainMenu.Items[6].Enabled = false;

                }
                btnNext.Text = "Next";
                // mainMenu.Items[7].Enabled = false;
                break;
            case 3:
                mvwCandidateBriefDetails.ActiveViewIndex = 2;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = false;
                /*mainMenu.Items[4].Enabled = false;
                mainMenu.Items[5].Enabled = false;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                {
                    mainMenu.Items[6].Enabled = false;

                }
                btnNext.Text = "Next";
                //mainMenu.Items[7].Enabled = false;
                break;
            case 4:
                mvwCandidateBriefDetails.ActiveViewIndex = 3;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                /*mainMenu.Items[4].Enabled = false;
                mainMenu.Items[5].Enabled = false;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                {
                    mainMenu.Items[6].Enabled = false;

                }
                btnNext.Text = "Next";
                // mainMenu.Items[7].Enabled = false;
                break;
            case 5:
                mvwCandidateBriefDetails.ActiveViewIndex = 4;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                /*mainMenu.Items[4].Enabled = true;
                mainMenu.Items[5].Enabled = false;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                {
                    mainMenu.Items[6].Enabled = false;
                }
                btnNext.Text = "Next";
                //mainMenu.Items[7].Enabled = false;
                break;
            case 6:
                mvwCandidateBriefDetails.ActiveViewIndex = 5;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                /*mainMenu.Items[4].Enabled = true;
                mainMenu.Items[5].Enabled = true;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                {
                    mainMenu.Items[6].Enabled = false;
                    btnNext.Text = "Next";

                }
                else
                {
                    btnNext.Text = "Finish";
                }



                // mainMenu.Items[7].Enabled = false;
                break;
            //case 7:
            //    mvwCandidateBriefDetails.ActiveViewIndex = 6;
            //    btnPervious.Visible = true;
            //    btnNext.Visible = true;
            //    btnFinish.Visible = false;
            //    mainMenu.Items[0].Enabled = true;
            //    mainMenu.Items[1].Enabled = true;
            //    mainMenu.Items[2].Enabled = true;
            //    mainMenu.Items[3].Enabled = true;
            //    mainMenu.Items[4].Enabled = true;
            //    mainMenu.Items[5].Enabled = true;
            //    mainMenu.Items[6].Enabled = true;
            //mainMenu.Items[7].Enabled = false;
            //break;
        }
    }

    private void NextBothClick()
    {
        switch (mvwCandidateBriefDetails.ActiveViewIndex)
        {
            case 0:
                if (Convert.ToInt16(hdnStageMode.Value) == 1 && Convert.ToInt16(hdnCandidateStatus.Value) == 22)
                {
                    string strReturnValue;


                    strReturnValue = SaveCandidateBriefDetail();
                    if (strReturnValue == "SUCCESS")
                    {
                        hdnCandidateStatus.Value = "5";

                        if (rbtQuestion.SelectedValue == "YES")
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('You have submitted Question to Regional Director, Please wait for Reply and then proceed for Proposal Submission.');", true);
                        }


                    }
                }
                StageWiseDisable(false);
                mvwCandidateBriefDetails.ActiveViewIndex = 1;
                btnPervious.Visible = true;
                btnNext.Visible = true;

                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = false;
                mainMenu.Items[3].Enabled = false;
                /*mainMenu.Items[4].Enabled = false;
                mainMenu.Items[5].Enabled = false;*/

                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                { mainMenu.Items[6].Enabled = false; }

                break;
            case 1:
                if (Convert.ToInt16(hdnProposalStageMode.Value) == 1 && Convert.ToInt16(hdnCandidateStatus.Value) == 5)
                {
                    string strReturnValue;
                    strReturnValue = SaveCandidateBriefDetail();
                    if (strReturnValue == "SUCCESS")
                    {
                        hdnCandidateStatus.Value = "6";
                        DataSet objDs = new DataSet();
                        objDs = GetCandidateBriefDetails();
                        if (objDs.Tables[5].Rows.Count > 0)
                        {
                            gvCandidateSelectAssessordate.DataSource = objDs.Tables[5];
                            gvCandidateSelectAssessordate.DataBind();
                        }
                    }
                }

                StageWiseDisable(false);
                mvwCandidateBriefDetails.ActiveViewIndex = 2;
                btnPervious.Visible = true;
                //brijal change as on 09112017
                if (tdPreFinish.Visible) 
                    btnNext.Visible = false;
                else
                    btnNext.Visible = true;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = false;
                /*mainMenu.Items[4].Enabled = false;
                mainMenu.Items[5].Enabled = false;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                { mainMenu.Items[6].Enabled = false; }


                break;
            case 2:
                if (Convert.ToInt16(hdnGDStageMode.Value) == 1 && Convert.ToInt16(hdnCandidateStatus.Value) == 6)
                {
                    string strReturnValue;
                    strReturnValue = SaveCandidateBriefDetail();
                    if (strReturnValue == "SUCCESS")
                    {
                        hdnCandidateStatus.Value = "7";
                    }
                }
                StageWiseDisable(false);
                mvwCandidateBriefDetails.ActiveViewIndex = 3;
                btnPervious.Visible = true;
                //brijal change as on 09112017
                if (tdPreFinish.Visible)
                    btnNext.Visible = false;
                else
                    btnNext.Visible = false; // true;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                /*mainMenu.Items[4].Enabled = false;
                mainMenu.Items[5].Enabled = false;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                { mainMenu.Items[6].Enabled = false; }


                break;
            case 3:
                if (Convert.ToInt16(hdnCAStageMode.Value) == 1 && Convert.ToInt16(hdnCandidateStatus.Value) == 7)
                {
                    string strReturnValue;
                    strReturnValue = SaveCandidateBriefDetail();
                    if (strReturnValue == "SUCCESS")
                    {
                        hdnCandidateStatus.Value = "8";
                    }
                }
                StageWiseDisable(false);
                mvwCandidateBriefDetails.ActiveViewIndex = 4;
                btnPervious.Visible = true;
                //brijal change as on 09112017
                if (tdPreFinish.Visible)
                    btnNext.Visible = false;
                else
                    btnNext.Visible = false; // true;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                /*mainMenu.Items[4].Enabled = true;
                mainMenu.Items[5].Enabled = false;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                { mainMenu.Items[6].Enabled = false; }


                break;
            case 4:
                StageWiseDisable(false);
                mvwCandidateBriefDetails.ActiveViewIndex = 5;
                btnPervious.Visible = true;
                //brijal change as on 09112017
                if (tdPreFinish.Visible)
                    btnNext.Visible = false;
                else
                    btnNext.Visible = false; // true;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                /*mainMenu.Items[4].Enabled = true;
                mainMenu.Items[5].Enabled = true;*/
                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                {
                    mainMenu.Items[6].Enabled = true;
                    btnNext.Text = "Next";
                }
                else
                {
                    btnNext.Text = "Finish";
                    if (hdnCandidateStageComplted.Value == "24" || hdnCandidateStatus.Value == "8")
                    {
                        btnNext.Visible = false;
                    }
                    else
                    {
                        btnNext.Visible = true;
                    }
                }

                break;
            case 5:
                if (Convert.ToInt16(hdnMRStageMode.Value) == 1 && Convert.ToInt16(hdnCandidateStatus.Value) == 8)
                {
                    string strReturnValue;
                    strReturnValue = SaveCandidateBriefDetail();
                    if (strReturnValue == "SUCCESS")
                    {
                        hdnCandidateStatus.Value = "24";
                        Response.Redirect("CandidateBriefThank.aspx", true);
                    }
                }
                StageWiseDisable(false);
                //mvwCandidateBriefDetails.ActiveViewIndex = 6;
                btnPervious.Visible = true;
                //brijal change as on 09112017
                if (tdPreFinish.Visible)
                    btnNext.Visible = false;
                else
                    btnNext.Visible = true;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                /*mainMenu.Items[4].Enabled = true;
                mainMenu.Items[5].Enabled = true;*/

                if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
                {
                    mvwCandidateBriefDetails.ActiveViewIndex = 6;
                    mainMenu.Items[6].Enabled = true;
                    btnNext.Text = "Next";
                }
                else
                {
                    btnNext.Text = "Finish";
                    if (hdnCandidateStageComplted.Value == "24" )
                    {
                        btnNext.Visible = false;
                    }
                    else
                    {
                        btnNext.Visible = true;
                    }
                }

                break;
            case 6:
                mvwCandidateBriefDetails.ActiveViewIndex = 6;
                btnPervious.Visible = true;
                btnNext.Visible = false;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                /*mainMenu.Items[4].Enabled = true;
                mainMenu.Items[5].Enabled = true;*/
                mainMenu.Items[6].Enabled = true;
                break;
        }
    }

    //all candidate type
    private DataSet GetCandidateBriefDetails()
    {
        DataSet objDs = null;
        try
        {
            //todo  CommonUtility.GetLoggedOnUserId()
            objDs = new CandidateBriefDetailBAL().GetCandidateBriefByCandidateID(CommonUtility.GetLoggedOnUserId(), Convert.ToInt16(hdnBriefID.Value));

        }
        catch (Exception exception)
        {
            exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;

    }

    //all candidate type
    private string SaveCandidateBriefDetail()
    {
        CandidateBriefDetailBAL objCBDBAL = new CandidateBriefDetailBAL();
        string strReturnValue;

        strReturnValue = (string)objCBDBAL.SetCandidateBriefByStatusID(CommonUtility.GetLoggedOnUserId(), Convert.ToInt32(hdnCandidateBriefId.Value), Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value), Convert.ToInt16(hdnCandidateStatus.Value), txtQuestionAssessor.Text.Trim(), Convert.ToBoolean(rbtQuestion.Items[0].Selected));
        return strReturnValue;
    }

    //all candidate type
    private void SaveDocument(string strFileType, int ModeratorType = 0, string ExternalAssessorName = "", int GDCandidateID = 0)
    {
        string strPath = string.Empty;
        string strFileExt = string.Empty;
        string strFileName = string.Empty;

        if (strFileType == "PROPOSAL")
        {
            strFileExt = Path.GetExtension(filProposal.PostedFile.FileName);
            strFileName = Path.GetFileNameWithoutExtension(filProposal.FileName);
            strPath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["ProposalPath"]));

            CandidateBriefDetailBAL objCBDBAL = new CandidateBriefDetailBAL();
            strFileName = (string)objCBDBAL.SetCandidateBriefDocument(CommonUtility.GetLoggedOnUserId(), Convert.ToInt32(hdnCandidateBriefId.Value), Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value), Convert.ToInt16(hdnCandidateStatus.Value), 1, strFileName, strFileExt, txtComments.Text.Trim());
            if (strFileName != "ERROR")
            {
                CommonUtility.SaveFile(filProposal, strPath, strFileName);
                gvProposalDocument.DataSource = objCBDBAL.GetCandidateBriefDocumentByDocumentType(1, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
                gvProposalDocument.DataBind();
            }

        }
        else if (strFileType == "GDDOCUMENT")
        {
            strFileExt = Path.GetExtension(filGDDocument.PostedFile.FileName);
            strFileName = Path.GetFileNameWithoutExtension(filGDDocument.FileName);
            strPath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["ProposalPath"]));

            CandidateBriefDetailBAL objCBDBAL = new CandidateBriefDetailBAL();
            strFileName = (string)objCBDBAL.SetCandidateGroupDiscussionGuide("UPDATE", ModeratorType, ExternalAssessorName, CommonUtility.GetLoggedOnUserId(), Convert.ToInt32(hdnCandidateBriefId.Value), Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value), Convert.ToInt16(hdnCandidateStatus.Value), 2, strFileName, strFileExt, "", GDCandidateID);

            if (strFileName != "ERROR")
            {
                CommonUtility.SaveFile(filGDDocument, strPath, strFileName);
                gvGDDocument.DataSource = objCBDBAL.GetCandidateBriefDocumentByDocumentType(2, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
                gvGDDocument.DataBind();
            }
        }
        else if (strFileType == "CONTENTANALYSIS")
        {
            strFileExt = Path.GetExtension(fileContentAnalysis.PostedFile.FileName);
            strFileName = Path.GetFileNameWithoutExtension(fileContentAnalysis.FileName);
            strPath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["ProposalPath"]));

            CandidateBriefDetailBAL objCBDBAL = new CandidateBriefDetailBAL();
            strFileName = (string)objCBDBAL.SetCandidateBriefDocument(CommonUtility.GetLoggedOnUserId(), Convert.ToInt32(hdnCandidateBriefId.Value), Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value), Convert.ToInt16(hdnCandidateStatus.Value), 3, strFileName, strFileExt, txtContentAnalysis.Text.Trim());
            if (strFileName != "ERROR")
            {
                CommonUtility.SaveFile(fileContentAnalysis, strPath, strFileName);
                gvContentAnalysis.DataSource = objCBDBAL.GetCandidateBriefDocumentByDocumentType(3, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
                gvContentAnalysis.DataBind();
            }
        }
        else if (strFileType == "PASTRESEARCH")
        {
            strFileExt = Path.GetExtension(filePastResearch.PostedFile.FileName);
            strFileName = Path.GetFileNameWithoutExtension(filePastResearch.FileName);
            strPath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["ProposalPath"]));

            CandidateBriefDetailBAL objCBDBAL = new CandidateBriefDetailBAL();
            strFileName = (string)objCBDBAL.SetCandidateBriefDocument(CommonUtility.GetLoggedOnUserId(), Convert.ToInt32(hdnCandidateBriefId.Value), Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value), Convert.ToInt16(hdnCandidateStatus.Value), 4, strFileName, strFileExt, txtPastResearch.Text.Trim());
            if (strFileName != "ERROR")
            {
                CommonUtility.SaveFile(filePastResearch, strPath, strFileName);
                gvPastResearch.DataSource = objCBDBAL.GetCandidateBriefDocumentByDocumentType(4, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
                gvPastResearch.DataBind();
            }
        }
        else if (strFileType == "MRRESEARCH")
        {
            strFileExt = Path.GetExtension(fileMRResearch.PostedFile.FileName);
            strFileName = Path.GetFileNameWithoutExtension(fileMRResearch.FileName);
            strPath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["ProposalPath"]));

            CandidateBriefDetailBAL objCBDBAL = new CandidateBriefDetailBAL();
            strFileName = (string)objCBDBAL.SetCandidateBriefDocument(CommonUtility.GetLoggedOnUserId(), Convert.ToInt32(hdnCandidateBriefId.Value), Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value), Convert.ToInt16(hdnCandidateStatus.Value), 5, strFileName, strFileExt, txtMRResearch.Text.Trim());
            if (strFileName != "ERROR")
            {
                CommonUtility.SaveFile(fileMRResearch, strPath, strFileName);
                gvMRResearch.DataSource = objCBDBAL.GetCandidateBriefDocumentByDocumentType(5, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
                gvMRResearch.DataBind();
            }
        }
        else if (strFileType == "STDOCUMENT")
        {
            strFileExt = Path.GetExtension(filStuDocument.PostedFile.FileName);
            strFileName = Path.GetFileNameWithoutExtension(filStuDocument.FileName);
            strPath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["ProposalPath"]));

            CandidateBriefDetailBAL objCBDBAL = new CandidateBriefDetailBAL();
            strFileName = (string)objCBDBAL.SetCandidateBriefDocument(CommonUtility.GetLoggedOnUserId(), Convert.ToInt32(hdnCandidateBriefId.Value), Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value), Convert.ToInt16(hdnCandidateStatus.Value), 10, strFileName, strFileExt, "");
            if (strFileName != "ERROR")
            {
                CommonUtility.SaveFile(filStuDocument, strPath, strFileName);
                gvStDocument.DataSource = objCBDBAL.GetCandidateBriefDocumentByDocumentType(10, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
                gvStDocument.DataBind();
            }
        }
    }

    //all candidate type
    protected void rbtQuestion_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rbtQuestion.SelectedValue == "YES")
        {
            trAssessorComments.Visible = true;
            trQuestion.Visible = true;
            trQuestionSpace1.Visible = true;
            trQuestionSpace2.Visible = true;

        }
        else
        {
            trAssessorComments.Visible = false;
            trQuestion.Visible = false;
            trQuestionSpace1.Visible = false;
            trQuestionSpace2.Visible = false;
        }
    }

    protected void cstProposal_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (filProposal.PostedFile == null)
        {
            args.IsValid = false;
            cstProposal.ErrorMessage = "Select file to attach.";
            return;
        }
        else
        {
            if (filProposal.PostedFile.FileName == "")
            {
                args.IsValid = false;
                cstProposal.ErrorMessage = "Select file to attach.";
                return;
            }
            else if (filProposal.PostedFile.FileName != "")
            {
                /*check file is valid*/
                if (filProposal.PostedFile.ContentLength == 0)
                {
                    args.IsValid = false;
                    cstProposal.ErrorMessage = "Select Valid file.";
                    return;
                }


                string pattern = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileName"]);
                Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
                Match match = regex.Match(Path.GetFileNameWithoutExtension(filProposal.FileName));

                if (!match.Success)
                {
                    args.IsValid = false;
                    cstProposal.ErrorMessage = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileNameErrorMsg"]);
                    return;
                }

                /*Check file name has extension*/
                if (System.IO.Path.HasExtension(filProposal.PostedFile.FileName) == true)
                {

                    /*check void extension are there or not*/
                    if (CommonUtility.CheckExtension(Path.GetExtension(filProposal.PostedFile.FileName), Convert.ToString(ConfigurationManager.AppSettings["ProposalFileType"])) == false)
                    {
                        args.IsValid = false;
                        cstProposal.ErrorMessage = "Upload File failed. Select file format as per below.";
                        return;
                    }


                    int fileSize = filProposal.PostedFile.ContentLength;

                    if (fileSize > (FileLimitSize))
                    {
                        args.IsValid = false;
                        cstProposal.ErrorMessage = "Document" + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]);
                        return;
                    }
                }
            }
        }
    }

    protected void cstAssessorName_ServerValidate(object source, ServerValidateEventArgs args)
    {
        //if (ddlInternal_External.SelectedValue == "2" && txtAssessorName.Text.Trim() == "")
        //{
        //    args.IsValid = false;
        //    return;
        //}

    }

    protected void cstCandidateName_ServerValidate(object source, ServerValidateEventArgs args)
    {
        //if (ddlInternal_External.SelectedValue == "1" && txtCandidateName.Text.Trim() == "")
        //{
        //    args.IsValid = false;
        //    return;
        //}
    }
    protected void btnGDDocument_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            try
            {
                int ModeratorType = 0;// Convert.ToInt16(ddlInternal_External.SelectedValue);
                int GDCandidateId = hdnGDCandidateID.Value != "" ? Convert.ToInt32(hdnGDCandidateID.Value) : 0;
                string ExternalAssessorName = txtAssessorName.Text.Trim();
                SaveDocument("GDDOCUMENT", ModeratorType, ExternalAssessorName, GDCandidateId);

            }
            catch (Exception ex)
            {
                lblMessage.Text = "Error while saving Record : " + ex.Message;

            }
            finally
            {
                //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Discussion Guide Uploaded Successfully.');", true);
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Discussion Guide Uploaded Successfully. Your Assessor can access your documents only after you click -FINISH on the last page of portal before logging out. ');", true);
                
            }
            btnGDDocument.Focus();
        }
    }


    protected void cstGDDocument_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (filGDDocument.PostedFile == null)
        {
            args.IsValid = false;
            cstGDDocument.ErrorMessage = "Select file to attach.";
            return;
        }
        else
        {
            if (filGDDocument.PostedFile.FileName == "")
            {
                args.IsValid = false;
                cstGDDocument.ErrorMessage = "Select file to attach.";
                return;
            }
            else if (filGDDocument.PostedFile.FileName != "")
            {
                /*check file is valid*/
                if (filGDDocument.PostedFile.ContentLength == 0)
                {
                    args.IsValid = false;
                    cstGDDocument.ErrorMessage = "Select Valid file.";
                    return;
                }

                string pattern = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileName"]);
                Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
                Match match = regex.Match(Path.GetFileNameWithoutExtension(filGDDocument.FileName));

                if (!match.Success)
                {
                    args.IsValid = false;
                    cstGDDocument.ErrorMessage = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileNameErrorMsg"]);
                    return;
                }

                /*Check file name has extension*/
                if (System.IO.Path.HasExtension(filGDDocument.PostedFile.FileName) == true)
                {

                    /*check void extension are there or not*/
                    if (CommonUtility.CheckExtension(Path.GetExtension(filGDDocument.PostedFile.FileName), Convert.ToString(ConfigurationManager.AppSettings["ProposalFileType"])) == false)
                    {
                        args.IsValid = false;
                        cstGDDocument.ErrorMessage = "Upload File failed. Select file format as per below.";
                        return;
                    }

                    int fileSize = filGDDocument.PostedFile.ContentLength;

                    if (fileSize > (FileLimitSize))
                    {
                        args.IsValid = false;
                        cstGDDocument.ErrorMessage = "Document" + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]); //"Document size should not be more than 5 MB.";
                        return;
                    }

                }
            }
        }
    }


    protected void cstGDAssessorCalanderMandatory_ServerValidate(object source, ServerValidateEventArgs args)
    {
        DataSet objDs = new DataSet();
        objDs = GetCandidateBriefDetails();

        if (objDs.Tables[4].Rows.Count == 0)
        {
            args.IsValid = false;
            cstGDAssessorCalanderMandatory.ErrorMessage = "After blocking calendar & entering group discussion details. Please click on save button.";
            return;
        }
    }
    protected void cstGDDocumentMandatory_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (gvGDDocument.Rows.Count <= 0)
        {
            args.IsValid = false;
            cstGDDocumentMandatory.ErrorMessage = "Upload group discussion document to proceed next stage.";
            return;
        }
    }

    protected void cstSTDocument_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (filStuDocument.PostedFile == null)
        {
            args.IsValid = false;
            cstSTDocument.ErrorMessage = "Select file to attach.";
            return;
        }
        else
        {
            if (filStuDocument.PostedFile.FileName == "")
            {
                args.IsValid = false;
                cstSTDocument.ErrorMessage = "Select file to attach.";
                return;
            }
            else if (filStuDocument.PostedFile.FileName != "")
            {
                /*check file is valid*/
                if (filStuDocument.PostedFile.ContentLength == 0)
                {
                    args.IsValid = false;
                    cstSTDocument.ErrorMessage = "Select Valid file.";
                    return;
                }

                string pattern = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileName"]);
                Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
                Match match = regex.Match(Path.GetFileNameWithoutExtension(filStuDocument.FileName));

                if (!match.Success)
                {
                    args.IsValid = false;
                    cstSTDocument.ErrorMessage = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileNameErrorMsg"]);
                    return;
                }

                /*Check file name has extension*/
                if (System.IO.Path.HasExtension(filStuDocument.PostedFile.FileName) == true)
                {

                    /*check void extension are there or not*/
                    if (CommonUtility.CheckExtension(Path.GetExtension(filStuDocument.PostedFile.FileName), Convert.ToString(ConfigurationManager.AppSettings["VideoFileType"])) == false)
                    {
                        args.IsValid = false;
                        cstSTDocument.ErrorMessage = "Upload File failed. Select file format as per below.";
                        return;
                    }

                    Int64 fileSize = filStuDocument.PostedFile.ContentLength;

                    if (fileSize > (VideoSizeLimit))
                    {
                        args.IsValid = false;
                        cstSTDocument.ErrorMessage = Convert.ToString(ConfigurationManager.AppSettings["StimuluVideoSizeUpdated"]);// "Video size should not be more than 10 MB.";
                        return;
                    }
                }
            }
        }
    }

    protected void cstGDCandidateTime_ServerValidate(object source, ServerValidateEventArgs args)
    {

        string sHr = "";

        //validation required

        if (ddlAMPM.SelectedValue == "PM")
        {
            if (ddlHour.SelectedValue == "12")
            {
                sHr = (00).ToString("00");
            }
            else
            {
                sHr = (Convert.ToInt32(ddlHour.SelectedValue) + 12).ToString("00");

            }
        }
        else
        {
            sHr = ddlHour.SelectedValue;
        }

        string sMin = ddlMinute.SelectedValue;
        bool flag = false;

        foreach (GridViewRow item in gvCandidateSelectAssessordate.Rows)
        {
            CheckBox chkApproveFirstHalf = (CheckBox)item.FindControl("chkApproveFirstHalf");
            CheckBox chkApproveSecondHalf = (CheckBox)item.FindControl("chkApproveSecondHalf");
            CheckBox chkCandidateFirstHalf = (CheckBox)item.FindControl("chkCandidateFirstHalf");
            CheckBox chkCandidateSecondHalf = (CheckBox)item.FindControl("chkCandidateSecondHalf");

            Label lblFHHour = (Label)item.FindControl("lblFHHour");
            Label lblFHMinute = (Label)item.FindControl("lblFHMinute");
            Label lblSHHour = (Label)item.FindControl("lblSHHour");
            Label lblSHMinute = (Label)item.FindControl("lblSHMinute");

            if (chkApproveFirstHalf.Checked && chkApproveSecondHalf.Checked && chkCandidateFirstHalf.Checked && chkCandidateSecondHalf.Checked)
            {
                flag = true;
            }
            else if (chkApproveFirstHalf.Checked && chkApproveSecondHalf.Checked && ((chkCandidateFirstHalf.Checked) || (chkCandidateSecondHalf.Checked)))
            {
                if (chkCandidateFirstHalf.Checked == true)
                {
                    TimeSpan dtCandidateTime = TimeSpan.Parse(sHr + ":" + sMin + ":00");
                    TimeSpan dtFirst = TimeSpan.Parse(lblFHHour.Text + ":" + lblFHMinute.Text + ":00");
                    TimeSpan dtFirstHalf = TimeSpan.Parse("12:00:00");

                    if (dtCandidateTime >= dtFirst && dtCandidateTime <= dtFirstHalf)
                    {
                        flag = true;
                    }
                }

                if (chkCandidateSecondHalf.Checked == true)
                {
                    TimeSpan dtCandidateTime = TimeSpan.Parse(sHr + ":" + sMin + ":00");

                    string SHHour = "";

                    if (ddlHour.SelectedValue == "12")
                    {
                        SHHour = (00).ToString("00");
                    }
                    else
                    {
                        SHHour = (Convert.ToInt32(lblSHHour.Text) + 12).ToString("00");
                    }

                    TimeSpan dtSecond = TimeSpan.Parse(SHHour + ":" + lblSHMinute.Text + ":00");
                    TimeSpan dtSecondHalf = TimeSpan.Parse("23:55:00");

                    if (dtCandidateTime >= dtSecond && dtCandidateTime <= dtSecondHalf)
                    {
                        flag = true;
                    }
                }

            }
            else if (chkApproveFirstHalf.Checked && chkCandidateFirstHalf.Checked)
            {
                TimeSpan dtCandidateTime = TimeSpan.Parse(sHr + ":" + sMin + ":00");
                TimeSpan dtFirst = TimeSpan.Parse(lblFHHour.Text + ":" + lblFHMinute.Text + ":00");
                TimeSpan dtFirstHalf = TimeSpan.Parse("12:00:00");

                if (dtCandidateTime >= dtFirst && dtCandidateTime <= dtFirstHalf)
                {
                    flag = true;
                }
            }
            else if (chkApproveSecondHalf.Checked && chkCandidateSecondHalf.Checked)
            {
                TimeSpan dtCandidateTime = TimeSpan.Parse(sHr + ":" + sMin + ":00");

                string SHHour = "";

                if (ddlHour.SelectedValue == "12")
                {
                    SHHour = (00).ToString("00");
                }
                else
                {
                    SHHour = (Convert.ToInt32(lblSHHour.Text) + 12).ToString("00");
                }

                TimeSpan dtSecond = TimeSpan.Parse(SHHour + ":" + lblSHMinute.Text + ":00");
                TimeSpan dtSecondHalf = TimeSpan.Parse("23:55:00");

                if (dtCandidateTime >= dtSecond && dtCandidateTime <= dtSecondHalf)
                {
                    flag = true;
                }
            }
        }


        if (!flag)
        {
            args.IsValid = false;
            cstAssessorDate.ErrorMessage = "Select Time As Per Assessor Availability";
            return;
        }
    }

    protected void cstAssessorDate_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (gvCandidateSelectAssessordate.Rows.Count > 0)
        {
            bool flag = false;
            int iCnt = 0;

            CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();

            foreach (GridViewRow item in gvCandidateSelectAssessordate.Rows)
            {
                CheckBox chkApproveFirstHalf = (CheckBox)item.FindControl("chkApproveFirstHalf");
                CheckBox chkApproveSecondHalf = (CheckBox)item.FindControl("chkApproveSecondHalf");
                CheckBox chkCandidateFirstHalf = (CheckBox)item.FindControl("chkCandidateFirstHalf");
                CheckBox chkCandidateSecondHalf = (CheckBox)item.FindControl("chkCandidateSecondHalf");
                Label lblAssessorCalendarDetailID = (Label)item.FindControl("lblAssessorCalendarDetailID");

                if (chkCandidateFirstHalf.Checked || chkCandidateSecondHalf.Checked)
                {
                    flag = true;
                    iCnt++;

                 /*   if (Convert.ToInt64(hdnPartnerID.Value) > 0)
                    {
                        if (objCandidateBriefDetailBAL.GetAssessorAvailability(Convert.ToInt32(lblAssessorCalendarDetailID.Text), 1, 0, "AM", Convert.ToInt64(hdnCandidateID.Value), Convert.ToInt64(hdnBriefID.Value)).Tables[0].Rows.Count > 0)
                        {
                            args.IsValid = false;
                            cstAssessorDate.ErrorMessage = "Assessor Already Assigned To Other Candidate For Selected Time.";
                            return;
                        }
                    }
                    else*/
                    {
                        if (chkCandidateFirstHalf.Checked)
                        {
                            if (objCandidateBriefDetailBAL.GetAssessorAvailability(Convert.ToInt32(lblAssessorCalendarDetailID.Text), 1, 0, "AM", Convert.ToInt64(hdnCandidateID.Value), Convert.ToInt64(hdnBriefID.Value)).Tables[0].Rows.Count > 0)
                            {
                                args.IsValid = false;
                                cstAssessorDate.ErrorMessage = "Assessor Already Assigned To Other Candidate For Selected Time.";
                                return;
                            }
                        }

                        if (chkCandidateSecondHalf.Checked)
                        {
                            if (objCandidateBriefDetailBAL.GetAssessorAvailability(Convert.ToInt32(lblAssessorCalendarDetailID.Text), 0, 1, "PM", Convert.ToInt64(hdnCandidateID.Value), Convert.ToInt64(hdnBriefID.Value)).Tables[0].Rows.Count > 0)
                            {
                                args.IsValid = false;
                                cstAssessorDate.ErrorMessage = "Assessor Already Assigned To Other Candidate For Selected Time.";
                                return;
                            }

                        }
                    }


                }
            }
            if (!flag)
            {
                args.IsValid = false;
                cstAssessorDate.ErrorMessage = "Select Atleast One Time";
                return;
            }
            if (iCnt != 1)
            {
                args.IsValid = false;
                cstAssessorDate.ErrorMessage = "Select Only One Day";
                return;
            }
        }

    }


    protected void cstContentAnalysis_ServerValidate(object source, ServerValidateEventArgs args)
    {

        if (fileContentAnalysis.PostedFile == null)
        {
            args.IsValid = false;
            cstContentAnalysis.ErrorMessage = "Select file to attach.";
            return;
        }
        else
        {
            if (fileContentAnalysis.PostedFile.FileName == "")
            {
                args.IsValid = false;
                cstContentAnalysis.ErrorMessage = "Select file to attach.";
                return;
            }
            else if (fileContentAnalysis.PostedFile.FileName != "")
            {
                /*check file is valid*/
                if (fileContentAnalysis.PostedFile.ContentLength == 0)
                {
                    args.IsValid = false;
                    cstContentAnalysis.ErrorMessage = "Select Valid file.";
                    return;
                }

                string pattern = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileName"]);
                Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
                Match match = regex.Match(Path.GetFileNameWithoutExtension(fileContentAnalysis.FileName));

                if (!match.Success)
                {
                    args.IsValid = false;
                    cstContentAnalysis.ErrorMessage = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileNameErrorMsg"]);
                    return;
                }

                /*Check file name has extension*/
                if (System.IO.Path.HasExtension(fileContentAnalysis.PostedFile.FileName) == true)
                {

                    /*check void extension are there or not*/
                    if (CommonUtility.CheckExtension(Path.GetExtension(fileContentAnalysis.PostedFile.FileName), Convert.ToString(ConfigurationManager.AppSettings["ProposalFileType"])) == false)
                    {
                        args.IsValid = false;
                        cstContentAnalysis.ErrorMessage = "Upload File failed. Select file format as per below.";
                        return;
                    }

                    int fileSize = fileContentAnalysis.PostedFile.ContentLength;

                    if (fileSize > (FileLimitSize))
                    {
                        args.IsValid = false;
                        cstContentAnalysis.ErrorMessage = "Document" + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]); //"Document size should not be more than 5 MB.";
                        return;
                    }
                }
            }
        }
    }


    protected void btnContentAnalysis_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            try
            {
                SaveDocument("CONTENTANALYSIS");
                txtContentAnalysis.Text = "";
            }
            catch (Exception ex)
            {
                lblMessage.Text = "Error while saving Record : " + ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Full Report Uploaded Successfully.');", true);
            }
        }
    }
    protected void cstPastResearch_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (filePastResearch.PostedFile == null)
        {
            args.IsValid = false;
            cstPastResearch.ErrorMessage = "Select file to attach.";
            return;
        }
        else
        {
            if (filePastResearch.PostedFile.FileName == "")
            {
                args.IsValid = false;
                cstPastResearch.ErrorMessage = "Select file to attach.";
                return;
            }
            else if (filePastResearch.PostedFile.FileName != "")
            {
                /*check file is valid*/
                if (filePastResearch.PostedFile.ContentLength == 0)
                {
                    args.IsValid = false;
                    cstPastResearch.ErrorMessage = "Select Valid file.";
                    return;
                }

                string pattern = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileName"]);
                Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
                Match match = regex.Match(Path.GetFileNameWithoutExtension(filePastResearch.FileName));

                if (!match.Success)
                {
                    args.IsValid = false;
                    cstPastResearch.ErrorMessage = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileNameErrorMsg"]);
                    return;
                }

                /*Check file name has extension*/
                if (System.IO.Path.HasExtension(filePastResearch.PostedFile.FileName) == true)
                {

                    /*check void extension are there or not*/
                    if (CommonUtility.CheckExtension(Path.GetExtension(filePastResearch.PostedFile.FileName), Convert.ToString(ConfigurationManager.AppSettings["ProposalFileType"])) == false)
                    {
                        args.IsValid = false;
                        cstPastResearch.ErrorMessage = "Upload File failed. Select file format as per below.";
                        return;
                    }

                    int fileSize = filePastResearch.PostedFile.ContentLength;

                    if (fileSize > (FileLimitSize))
                    {
                        args.IsValid = false;
                        cstPastResearch.ErrorMessage = "Document" + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]); //"Document size should not be more than 5 MB.";
                        return;
                    }

                }
            }
        }
    }
    protected void cstMRResearch_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (fileMRResearch.PostedFile == null)
        {
            args.IsValid = false;
            cstMRResearch.ErrorMessage = "Select file to attach.";

            return;
        }
        else
        {
            if (fileMRResearch.PostedFile.FileName == "")
            {
                args.IsValid = false;
                cstMRResearch.ErrorMessage = "Select file to attach.";
                return;
            }
            else if (fileMRResearch.PostedFile.FileName != "")
            {
                /*check file is valid*/
                if (fileMRResearch.PostedFile.ContentLength == 0)
                {
                    args.IsValid = false;
                    cstMRResearch.ErrorMessage = "Select Valid file.";
                    return;
                }

                string pattern = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileName"]);
                Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
                Match match = regex.Match(Path.GetFileNameWithoutExtension(fileMRResearch.FileName));

                if (!match.Success)
                {
                    args.IsValid = false;
                    cstMRResearch.ErrorMessage = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileNameErrorMsg"]);
                    return;
                }

                /*Check file name has extension*/
                if (System.IO.Path.HasExtension(fileMRResearch.PostedFile.FileName) == true)
                {

                    /*check void extension are there or not*/
                    if (CommonUtility.CheckExtension(Path.GetExtension(fileMRResearch.PostedFile.FileName), Convert.ToString(ConfigurationManager.AppSettings["ProposalFileType"])) == false)
                    {
                        args.IsValid = false;
                        cstMRResearch.ErrorMessage = "Upload File failed. Select file format as per below.";
                        return;
                    }


                    int fileSize = fileMRResearch.PostedFile.ContentLength;

                    if (fileSize > (FileLimitSize))
                    {
                        args.IsValid = false;
                        cstMRResearch.ErrorMessage = "Document" + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]); //"Document size should not be more than 5 MB.";
                        return;
                    }


                }
            }
        }
    }

    protected void btnAddPastResearch_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            try
            {
                SaveDocument("PASTRESEARCH");
                txtPastResearch.Text = "";
            }
            catch (Exception ex)
            {
                lblMessage.Text = "Error while saving Record : " + ex.Message;

            }
            finally
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert(' Past Research Uploaded Successfully.');", true);
            }
        }
    }
    protected void btnAddMRResearch_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            try
            {
                SaveDocument("MRRESEARCH");
                txtMRResearch.Text = "";
            }
            catch (Exception ex)
            {
                lblMessage.Text = "Error while saving Record : " + ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert(' Market Research Report Uploaded Successfully.');", true);
            }
        }
    }
    protected void btnMoreCommentAdd_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            try
            {
                SaveMoreDetails();
                txtCommentsMore.Enabled = false;
                btnMoreCommentCancel.Enabled = false;
                btnMoreCommentCancel.Visible = false;
                btnMoreCommentAdd.Enabled = false;
                btnMoreCommentAdd.Visible = false;
                lblCommentsMoresys.Text = Convert.ToString(System.DateTime.Now);
            }
            catch (Exception ex)
            {
                lblMessage.Text = "Error while saving Record : " + ex.Message;

            }
            finally
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Questions from Assessor Added Successfully.');", true);
            }

        }
    }

    private string SaveMoreDetails()
    {
        CandidateBriefDetailBAL objCBDBAL = new CandidateBriefDetailBAL();
        string strReturnValue;

        strReturnValue = (string)objCBDBAL.SetCandidateMoreComments(Convert.ToInt32(hdnMenuMoreDetail.Value), CommonUtility.GetLoggedOnUserId(), Convert.ToInt32(hdnCandidateBriefId.Value), 3, txtCommentsMore.Text.Trim());
        return strReturnValue;
    }

    private string LanguageList()
    {
        string strLanguageList = string.Empty;
        for (int i = 0; i < chkGroupDiscussionLanguage.Items.Count; i++)
        {
            if (chkGroupDiscussionLanguage.Items[i].Selected)
            {
                strLanguageList += chkGroupDiscussionLanguage.Items[i].Value + ",";
            }
        }
        return strLanguageList.Substring(0, (strLanguageList.Length - 1));
    }

    private void ClearDataGDDetails()
    {
        ddlGroupDiscussiontype.SelectedIndex = 0;
        txtGroupDiscussionLocation.Text = "";
        LanguageListClear();
    }

    private void LanguageListClear()
    {
        int count = chkGroupDiscussionLanguage.Items.Count;
        for (int i = 0; i < count; i++)
        {
            if (chkGroupDiscussionLanguage.Items[i].Selected == true)
            {
                chkGroupDiscussionLanguage.Items[i].Selected = false;
            }
        }
    }
    protected void btnCancelGDDetails_Click(object sender, EventArgs e)
    {

        ClearDataGDDetails();
    }
    protected void cstGroupDiscussionLanguage_ServerValidate(object source, ServerValidateEventArgs args)
    {
        int intlanguageCount = LanguageSelected();
        if (intlanguageCount <= 0)
        {
            cstGroupDiscussionLanguage.ErrorMessage = "Select Language.";
            args.IsValid = false;
            return;
        }
        else if (intlanguageCount > 1)
        {
            cstGroupDiscussionLanguage.ErrorMessage = "Select only One Language.";
            args.IsValid = false;
            return;
        }
    }

    private int LanguageSelected()
    {
        int intCount = 0;
        for (int i = 0; i < chkGroupDiscussionLanguage.Items.Count; i++)
        {
            if (chkGroupDiscussionLanguage.Items[i].Selected)
            {
                intCount = intCount + 1;
                //return intCount;
            }
        }
        return intCount;
    }
    protected void gvGroupDiscussion_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnkButton = (LinkButton)e.Row.FindControl("lnkDelete");

            lnkButton.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete?')");

        }
    }

    //protected void ddlInternal_External_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    if (ddlInternal_External.SelectedValue == "1")
    //    {
    //        trCandidateName.Visible = true;
    //        trRegistrationNumber.Visible = true;
    //        trAssessorName.Visible = false;
    //        trBlankRowCandidateName.Visible = true;
    //        trBlankRowRegistrationNumber.Visible = true;
    //    }
    //    else if (ddlInternal_External.SelectedValue == "2")
    //    {
    //        trCandidateName.Visible = false;
    //        trRegistrationNumber.Visible = false;
    //        trAssessorName.Visible = true;
    //        trBlankRowCandidateName.Visible = false;
    //        trBlankRowRegistrationNumber.Visible = false;
    //    }
    //    else
    //    {
    //        trCandidateName.Visible = false;
    //        trRegistrationNumber.Visible = false;
    //        trAssessorName.Visible = false;
    //        trBlankRowCandidateName.Visible = false;
    //        trBlankRowRegistrationNumber.Visible = false;
    //    }
    //}

    protected void cstGvProposalDocument_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (gvProposalDocument.Rows.Count <= 0)
        {
            args.IsValid = false;
            cstGvProposalDocument.ErrorMessage = "Upload proposal document to proceed next stage.";
            return;
        }
    }



    //protected void csvContentAnalysis_ServerValidate(object source, ServerValidateEventArgs args)
    //{

    //    if (gvContentAnalysis.Rows.Count <= 0)
    //    {
    //        args.IsValid = false;
    //        csvContentAnalysis.ErrorMessage = "Upload Content Analysis document to proceed next stage.";
    //        return;
    //    }
    //}
    //protected void cstGrdMRResearch_ServerValidate(object source, ServerValidateEventArgs args)
    //{
    //    if (gvMRResearch.Rows.Count <= 0)
    //    {
    //        args.IsValid = false;
    //        cstGrdMRResearch.ErrorMessage = "Upload MR Research document to complete accreditation process.";
    //        return;
    //    }
    //}
    //protected void lnkDownload_Click(object sender, EventArgs e)
    //{
    //    string strPath;
    //    string strAuthority = HttpContext.Current.Request.Url.Authority;

    //    string strBriefDocath = PathBriefDoc.Remove(0, 1);
    //    string strBriefName= txtHideanBTitle.Text.Trim();
    //    strPath = "http://" + strAuthority + strBriefDocath + strBriefName;


    //    string filePath = (sender as LinkButton).CommandArgument;
    //    Response.ContentType = ContentType;
    //    Response.AppendHeader("Content-Disposition", "attachment; filename=" + strPath);
    //    Response.WriteFile(filePath);
    //    Response.End();
    //}
    protected void btnCancelProposal_Click(object sender, EventArgs e)
    {
        txtComments.Text = "";
    }
    protected void btnCancelDocument_Click(object sender, EventArgs e)
    {

    }
    protected void btnCancelContentAnalysis_Click(object sender, EventArgs e)
    {
        txtContentAnalysis.Text = "";
    }
    protected void btnCancelPastResearch_Click(object sender, EventArgs e)
    {
        txtPastResearch.Text = "";
    }
    protected void btnCancelMRResearch_Click(object sender, EventArgs e)
    {
        txtMRResearch.Text = "";
    }


    private void DeleteDocuments(long intDeleteDocument, int intDocumentTypeID)
    {

        CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();
        string strReturnValue;
        strReturnValue = (string)objCandidateBriefDetailBAL.SetDeleteCandidateBriefDocument(CommonUtility.GetLoggedOnUserId(), hdnCandidateBriefId.Value, hdnCandidateID.Value, hdnBriefID.Value, intDeleteDocument);

        if (strReturnValue == "SUCCESS")
        {
            gvProposalDocument.DataSource = objCandidateBriefDetailBAL.GetCandidateBriefDocumentByDocumentType(intDocumentTypeID, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
            gvProposalDocument.DataBind();
        }
    }


    protected void gvProposalDocument_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnkButton = (LinkButton)e.Row.FindControl("lnkDelete");

            lnkButton.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete?')");

        }
    }
    protected void gvProposalDocument_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        long intGDID = (long)gvProposalDocument.DataKeys[e.RowIndex].Value;
        CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();
        DeleteDocuments(intGDID, 1);
        //gvProposalDocument.DataSource = objCandidateBriefDetailBAL.GetCandidateBriefDocumentByDocumentType(1, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
        //gvProposalDocument.DataBind();
    }

    private void DeleteGDDocuments(long intDeleteDocument, int intDocumentTypeID)
    {

        CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();
        string strReturnValue;
        strReturnValue = (string)objCandidateBriefDetailBAL.SetDeleteCandidateBriefDocument(CommonUtility.GetLoggedOnUserId(), hdnCandidateBriefId.Value, hdnCandidateID.Value, hdnBriefID.Value, intDeleteDocument);

        if (strReturnValue == "SUCCESS")
        {
            gvGDDocument.DataSource = objCandidateBriefDetailBAL.GetCandidateBriefDocumentByDocumentType(intDocumentTypeID, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
            gvGDDocument.DataBind();
        }
    }

    private void DeleteStDocuments(long intDeleteDocument, int intDocumentTypeID)
    {

        CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();
        string strReturnValue;
        strReturnValue = (string)objCandidateBriefDetailBAL.SetDeleteCandidateBriefDocument(CommonUtility.GetLoggedOnUserId(), hdnCandidateBriefId.Value, hdnCandidateID.Value, hdnBriefID.Value, intDeleteDocument);

        if (strReturnValue == "SUCCESS")
        {
            gvStDocument.DataSource = objCandidateBriefDetailBAL.GetCandidateBriefDocumentByDocumentType(intDocumentTypeID, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
            gvStDocument.DataBind();
        }
    }

    protected void gvGDDocument_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnkButton = (LinkButton)e.Row.FindControl("lnkDelete");

            lnkButton.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete?')");

        }
    }
    protected void gvGDDocument_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        long intGDID = (long)gvGDDocument.DataKeys[e.RowIndex].Value;
        CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();
        DeleteGDDocuments(intGDID, 2);
        //gvGDDocument.DataSource = objCandidateBriefDetailBAL.GetCandidateBriefDocumentByDocumentType(2, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
        //gvGDDocument.DataBind();
    }

    protected void gvStDocument_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnkButton = (LinkButton)e.Row.FindControl("lnkDelete");

            lnkButton.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete?')");

        }
    }
    protected void gvStDocument_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        long intGDID = (long)gvStDocument.DataKeys[e.RowIndex].Value;
        CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();
        DeleteStDocuments(intGDID, 10);
        //gvStDocument.DataSource = objCandidateBriefDetailBAL.GetCandidateBriefDocumentByDocumentType(10, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
        //gvStDocument.DataBind();
    }

    private void DeleteContentAnalysisDocuments(long intDeleteDocument, int intDocumentTypeID)
    {

        CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();
        string strReturnValue;
        strReturnValue = (string)objCandidateBriefDetailBAL.SetDeleteCandidateBriefDocument(CommonUtility.GetLoggedOnUserId(), hdnCandidateBriefId.Value, hdnCandidateID.Value, hdnBriefID.Value, intDeleteDocument);

        if (strReturnValue == "SUCCESS")
        {
            gvContentAnalysis.DataSource = objCandidateBriefDetailBAL.GetCandidateBriefDocumentByDocumentType(intDocumentTypeID, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
            gvContentAnalysis.DataBind();
        }
    }
    protected void gvContentAnalysis_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnkButton = (LinkButton)e.Row.FindControl("lnkDelete");

            lnkButton.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete?')");

        }
    }
    protected void gvContentAnalysis_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        long intGDID = (long)gvContentAnalysis.DataKeys[e.RowIndex].Value;
        CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();
        DeleteContentAnalysisDocuments(intGDID, 3);
        gvContentAnalysis.DataSource = objCandidateBriefDetailBAL.GetCandidateBriefDocumentByDocumentType(3, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
        gvContentAnalysis.DataBind();
    }
    private void DeletePastResearchDocuments(long intDeleteDocument, int intDocumentTypeID)
    {

        CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();
        string strReturnValue;
        strReturnValue = (string)objCandidateBriefDetailBAL.SetDeleteCandidateBriefDocument(CommonUtility.GetLoggedOnUserId(), hdnCandidateBriefId.Value, hdnCandidateID.Value, hdnBriefID.Value, intDeleteDocument);

        if (strReturnValue == "SUCCESS")
        {
            gvPastResearch.DataSource = objCandidateBriefDetailBAL.GetCandidateBriefDocumentByDocumentType(intDocumentTypeID, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
            gvPastResearch.DataBind();
        }
    }

    protected void gvPastResearch_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnkButton = (LinkButton)e.Row.FindControl("lnkDelete");

            lnkButton.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete?')");

        }
    }
    protected void gvPastResearch_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        long intGDID = (long)gvPastResearch.DataKeys[e.RowIndex].Value;
        CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();
        DeletePastResearchDocuments(intGDID, 4);
        //gvPastResearch.DataSource = objCandidateBriefDetailBAL.GetCandidateBriefDocumentByDocumentType(4, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
        //gvPastResearch.DataBind();
    }



    private void DeleteMRResearchDocuments(long intDeleteDocument, int intDocumentTypeID)
    {

        CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();
        string strReturnValue;
        strReturnValue = (string)objCandidateBriefDetailBAL.SetDeleteCandidateBriefDocument(CommonUtility.GetLoggedOnUserId(), hdnCandidateBriefId.Value, hdnCandidateID.Value, hdnBriefID.Value, intDeleteDocument);

        if (strReturnValue == "SUCCESS")
        {
            gvMRResearch.DataSource = objCandidateBriefDetailBAL.GetCandidateBriefDocumentByDocumentType(intDocumentTypeID, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
            gvMRResearch.DataBind();
        }
    }
    protected void gvMRResearch_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnkButton = (LinkButton)e.Row.FindControl("lnkDelete");

            lnkButton.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete?')");

        }
    }
    protected void gvMRResearch_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        long intGDID = (long)gvMRResearch.DataKeys[e.RowIndex].Value;
        CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();
        DeleteMRResearchDocuments(intGDID, 4);
        //gvMRResearch.DataSource = objCandidateBriefDetailBAL.GetCandidateBriefDocumentByDocumentType(4, Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value));
        //gvMRResearch.DataBind();
    }

    protected void btnStuDocument_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            try
            {
                SaveDocument("STDOCUMENT");
            }
            catch (Exception ex)
            {
                lblMessage.Text = "Error while saving Record : " + ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Stimulus Uploaded Successfully.');", true);
            }
            btnStuDocument.Focus();
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {

        string strReturnValue = "";
        if (Page.IsValid == true)
        {
            try
            {
                CandidateBriefDetailBAL objCandidateBriefDetailBAL = new CandidateBriefDetailBAL();

                bool CandidateFirstHalfCheck = false;
                bool CandidateSecondHalfCheck = false;

                string GDTime = "";

                if (ddlAMPM.SelectedValue == "PM")
                {
                    if (ddlHour.SelectedValue == "12")
                    {
                        GDTime = "00" + ":" + ddlMinute.SelectedValue + ":00";

                    }
                    else
                    {
                        GDTime = (Convert.ToInt32(ddlHour.SelectedValue) + 12).ToString("00") + ":" + ddlMinute.SelectedValue + ":00";
                    }
                }
                else
                {
                    GDTime = ddlHour.SelectedValue + ":" + ddlMinute.SelectedValue + ":00";
                }

                int AssessorCalendarID = 0;

                foreach (GridViewRow item in gvCandidateSelectAssessordate.Rows)
                {
                    CheckBox chkApproveFirstHalf = (CheckBox)item.FindControl("chkApproveFirstHalf");
                    CheckBox chkApproveSecondHalf = (CheckBox)item.FindControl("chkApproveSecondHalf");
                    CheckBox chkCandidateFirstHalf = (CheckBox)item.FindControl("chkCandidateFirstHalf");
                    CheckBox chkCandidateSecondHalf = (CheckBox)item.FindControl("chkCandidateSecondHalf");
                    Label lblAssessorCalendarDetailID = (Label)item.FindControl("lblAssessorCalendarDetailID");

                    if (chkCandidateFirstHalf.Checked)
                    {
                        CandidateFirstHalfCheck = true;
                        AssessorCalendarID = lblAssessorCalendarDetailID.Text != "" ? Convert.ToInt32(lblAssessorCalendarDetailID.Text) : 0;
                    }
                    else if (chkCandidateSecondHalf.Checked)
                    {
                        CandidateSecondHalfCheck = true;
                        AssessorCalendarID = lblAssessorCalendarDetailID.Text != "" ? Convert.ToInt32(lblAssessorCalendarDetailID.Text) : 0;
                    }
                }

                int GDCandidateID = hdnGDCandidateID.Value != "" ? Convert.ToInt32(hdnGDCandidateID.Value) : 0;
                int CandidateGDID = hdnCandidateGDID.Value != "" ? Convert.ToInt32(hdnCandidateGDID.Value) : 0;

                strReturnValue = (string)objCandidateBriefDetailBAL.SetCandidateGroupDiscussion("INSERT", CandidateGDID, hdnCandidateBriefId.Value, hdnCandidateID.Value, hdnBriefID.Value, ddlGroupDiscussiontype.SelectedValue, txtGroupDiscussionLocation.Text.Trim(), LanguageList().Trim(), CommonUtility.GetLoggedOnUserId(), GDTime, AssessorCalendarID, CandidateFirstHalfCheck, CandidateSecondHalfCheck, GDCandidateID);

            }
            catch (Exception ex)
            {
                lblMessage.Text = "Error while saving Record : " + ex.Message;
            }
            finally
            {
                if (strReturnValue == "SUCCESS")
                {
                    //string strNewMsg="\n\n Please Scroll down to upload GS & Stimulus";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Group discussion Slot addedd successfully. Please Scroll down to upload Discussion Guide & Stimulus.');", true);
                }
                else if (strReturnValue == "PARTNERERROR")
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Partner candidate still not completed proposal stage.');", true);
                }
                else if (strReturnValue == "ERROR")
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Group discussion Slot addedd successfully. Please Scroll down to upload Discussion Guide & Stimulus.');", true);
                }
            }
            btnSave.Focus();

        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        ClearDataGDDetails();
    }

    protected void gvCandidateSelectAssessordate_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        DataSet objDs = new DataSet();
        objDs = GetCandidateBriefDetails();
        gvCandidateSelectAssessordate.PageIndex = e.NewPageIndex;
        gvCandidateSelectAssessordate.DataSource = objDs.Tables[5];
        gvCandidateSelectAssessordate.DataBind();
    }
    protected void mvwCandidateBriefDetails_ActiveViewChanged(object sender, EventArgs e)
    {
        foreach (MenuItem item in mainMenu.Items)
        {
            item.Text = item.Text.RemoveHTMLTags();
        }

        if (mainMenu.Items[mvwCandidateBriefDetails.ActiveViewIndex] != null)
        {
            mainMenu.Items[mvwCandidateBriefDetails.ActiveViewIndex].Text = "<b><font color='blue'>" + mainMenu.Items[mvwCandidateBriefDetails.ActiveViewIndex].Text + "</font></b>";
        }

    }
    protected void cstGDPartnerValidation_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (Convert.ToInt64(hdnPartnerID.Value) > 0)
        {
            DataSet objDs = new DataSet();
            objDs = new CandidateBriefDetailBAL().GetGDPartnerValidation(hdnPartnerID.Value);

            if (Convert.ToInt64(objDs.Tables[0].Rows[0][0]) <= 0)
            {
                args.IsValid = false;
                cstGDPartnerValidation.ErrorMessage = "Perfered partner candidate still not completed proposal stage.";
                return;
            }
        }
    }
    protected void btnPreFinish_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            if (Convert.ToInt16(hdnGDStageMode.Value) == 1 && (Convert.ToInt16(hdnCandidateStatus.Value) == 6 || Convert.ToInt16(hdnCandidateStatus.Value) == 7|| Convert.ToInt16(hdnCandidateStatus.Value) == 8))
            {
                string strReturnValue; 
                CandidateBriefDetailBAL objCBDBAL = new CandidateBriefDetailBAL();
                strReturnValue = (string)objCBDBAL.SetCandidateBriefByStatusIDPreFinish(CommonUtility.GetLoggedOnUserId(), Convert.ToInt32(hdnCandidateBriefId.Value), Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value), Convert.ToInt16(hdnCandidateStatus.Value), txtQuestionAssessor.Text.Trim(), Convert.ToBoolean(rbtQuestion.Items[0].Selected));
                //strReturnValue = (string)objCBDBAL.SetCandidateBriefByStatusIDPreFinish(CommonUtility.GetLoggedOnUserId(), Convert.ToInt32(hdnCandidateBriefId.Value), Convert.ToInt32(hdnCandidateID.Value), Convert.ToInt16(hdnBriefID.Value), 8, txtQuestionAssessor.Text.Trim(), Convert.ToBoolean(rbtQuestion.Items[0].Selected));

                if (strReturnValue == "SUCCESS")
                {
                    hdnCandidateStatus.Value = "24";
                    Response.Redirect("CandidateBriefThank.aspx", true);
                }
            }
            StageWiseDisable(false);
            //mvwCandidateBriefDetails.ActiveViewIndex = 6;
            btnPervious.Visible = true;
            btnNext.Visible = false;
            mainMenu.Items[0].Enabled = true;
            mainMenu.Items[1].Enabled = true;
            mainMenu.Items[2].Enabled = true;
            mainMenu.Items[3].Enabled = true;
            /*mainMenu.Items[4].Enabled = true;
            mainMenu.Items[5].Enabled = true;*/

            if (Convert.ToInt32(hdnMenuMoreDetail.Value) > 0)
            {
                mvwCandidateBriefDetails.ActiveViewIndex = 6;
                mainMenu.Items[6].Enabled = true;
                btnNext.Text = "Next";
            }
            else
            {
                btnNext.Text = "Finish";
                if (hdnCandidateStageComplted.Value == "24")
                {
                    btnNext.Visible = false;
                }
                else
                {
                    btnNext.Visible = true;
                }
            }
             
        }
    }
}